<!--
 * @Author: qiaoxin
 * @Date: 2024-04-09 19:35:26
 * @LastEditors: qiaoxin
 * @LastEditTime: 2024-04-16 12:03:50
 * @Description: 
 * @FilePath: \erp-app\src\pages\pm\requirement\detail.vue
-->

<route lang="json5">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '任务单评审',
    enablePullDownRefresh: true,
    navigationStyle: 'custom',
  },
}
</route>

<template>
  <page-meta :root-font-size="setting.rootFontSize"></page-meta>
  <view style="min-height: 100vh; background-color: #f2f2f1">
    <view style="position: sticky; top: 0; z-index: 9999">
      <wd-navbar title="任务单评审" :bordered="false" safeAreaInsetTop>
        <template #left>
          <wd-icon name="thin-arrow-left" size="22px" color="white" @click="goBack"></wd-icon>
        </template>
      </wd-navbar>
    </view>
    <view style="flex: 1; overflow: auto">
      <!-- <th-card title="需求单信息">
      <th-form>
        <th-form-item label="需求单编号">
          <text class="text">{{ form.demandCode }}</text>
        </th-form-item>
        <th-form-item label="日期">
          <text class="text">{{ formatByDayjs(form.demandDate) }}</text>
        </th-form-item>
        <th-form-item label="客户">
          <text class="text">{{ form.cusCode }}</text>
        </th-form-item>
        <th-form-item label="需求类型">
          <text class="text">{{ form.demandType }}</text>
        </th-form-item>
        <th-form-item label="需求产品">
          <text class="text">{{ form.invName }}</text>
        </th-form-item>
        <th-form-item label="需求产品规格">
          <text class="text">{{ form.invStd }}</text>
        </th-form-item>
        <th-form-item label="是否有外来样">
          <text class="text">{{ form.sampleFlagName }}</text>
        </th-form-item>
      </th-form>
    </th-card> -->

      <th-card title="需求单信息">
        <th-form>
          <th-form-item label="需求产品">
            <text class="text">{{ form.invName }}</text>
          </th-form-item>
          <th-form-item label="需求产品规格">
            <text class="text">{{ form.invStd }}</text>
          </th-form-item>
          <th-form-item label="用途">
            <text class="text">{{ form.applicationType }}</text>
          </th-form-item>
          <th-form-item label="要求完成时间">
            <text class="text">{{ form.askCompleteTime }}</text>
          </th-form-item>

          <template v-if="showMoreDemand">
            <th-form-item label="需求单编号">
              <text class="text">{{ form.demandCode }}</text>
            </th-form-item>
            <th-form-item label="需求单日期">
              <text class="text">{{ formatByDayjs(form.demandDate) }}</text>
            </th-form-item>
            <th-form-item label="客户" v-if="form.cusCode">
              <text class="text">{{ form.cusCode }}</text>
            </th-form-item>

            <th-form-item label="业务员">
              <text class="text">{{ form.personName }}</text>
            </th-form-item>
            <th-form-item label="业务部门" v-if="form.deptName">
              <text class="text">{{ form.deptName }}</text>
            </th-form-item>
            <!-- <th-form-item label="所属公司" v-if="form.tenantName">
              <text class="text">{{ form.tenantName }}</text>
            </th-form-item> -->

            <th-form-item label="需求类型">
              <text class="text">{{ form.demandType }}</text>
            </th-form-item>

            <th-form-item label="年需求量/吨">
              <text class="text">{{ form.invDemand }}</text>
            </th-form-item>

            <th-form-item label="是否有外来样">
              <text class="text">{{ form.sampleFlagName }}</text>
            </th-form-item>
            <th-form-item label="外来样样品编码" v-show="form.sampleFlag != '0'">
              <text class="text">{{ form.sampleCode }}</text>
            </th-form-item>
            <th-form-item label="外来样样品数量" v-show="form.sampleFlag != '0'">
              <text class="text">{{ form.samplesNum }}{{ form.sampleUnit }}</text>
            </th-form-item>
            <th-form-item label="外来样批次" v-show="form.sampleFlag != '0'">
              <text class="text">{{ form.sampleBatch }}</text>
            </th-form-item>
            <th-form-item label="是否给客户提供样品">
              <text class="text">{{ form.requestFlag == '1' ? '是' : '否' }}</text>
            </th-form-item>
            <th-form-item label="给客户提供样品数量" v-if="form.requestFlag == '1'">
              <text class="text">{{ form.requestNum }}{{ form.requestNumUnit }}</text>
            </th-form-item>

            <th-form-item
              label="需求指标"
              labelPosition="top"
              v-show="checkTargetList && checkTargetList.length"
            >
              <view style="overflow: auto" class="table-container">
                <table class="analysis-table">
                  <tbody>
                    <tr>
                      <th style="width: 320rpx; min-width: 9.5rem">检验指标名称</th>
                      <th
                        style="width: 280rpx; min-width: 280rpx"
                        v-if="form.demandTypeCode != '42'"
                      >
                        U8指标
                      </th>
                      <th style="width: 280rpx; min-width: 280rpx">客户指标</th>
                      <th style="width: 280rpx; min-width: 280rpx">描述</th>
                    </tr>
                    <tr
                      align="center"
                      v-for="(item, index) in checkTargetList"
                      :key="index"
                      :class="[item.checktarget != item.cusCheckTarget ? 'line-red' : '']"
                    >
                      <td>
                        {{ item.standardName }}
                      </td>
                      <td v-if="form.demandTypeCode != '42'">
                        {{ item.standardValue }}
                      </td>
                      <td>
                        {{ item.standardValuePm }}
                      </td>
                      <td>
                        {{ item.standardDesc }}
                      </td>
                    </tr>
                  </tbody>
                </table>
              </view>
            </th-form-item>
          </template>
          <th-form-item
            label="附件"
            class="form-demandDesc form-file"
            v-if="form.rdDemandFileEntity && form.rdDemandFileEntity.length"
          >
            <view class="form-file-view">
              <view
                v-for="(file, index) in form.rdDemandFileEntity"
                :key="file.fileUrl"
                class="info-row-item"
              >
                <text @click="previewFileHandle(file.fileUrl)">{{ file.fileName }}</text>
              </view>
            </view>
          </th-form-item>
          <th-form-item label="需求描述" class="form-demandDesc" v-if="form.demandDesc">
            <text class="text">{{ form.demandDesc }}</text>
          </th-form-item>
          <th-form-item label="评审结论" class="form-demandDesc" v-if="form.reviewConclusiondemand">
            <text class="text">{{ form.reviewConclusiondemand }}</text>
          </th-form-item>
          <th-form-item label="评审结论描述" class="form-demandDesc" v-if="form.demandResult">
            <text class="text">{{ form.demandResult }}</text>
          </th-form-item>
          <view class="exportModel" @click="showMoreDemandhandle">
            <text>{{ showMoreDemand ? '收起' : '展开' }}</text>
          </view>
        </th-form>
      </th-card>

      <th-card
        title="子任务记录"
        v-if="form.rdTaskListAll && form.rdTaskListAll.length && taskTypeList.includes('10')"
      >
        <wd-collapse v-model="rdTaskListAllActiveKey">
          <wd-collapse-item
            v-for="item in form.rdTaskListAll"
            :key="item.id"
            :name="item.id"
            :title="item.title"
            :before-expend="beforeExpend"
            custom-class="custom-class-collapse"
          >
            <view>
              <view v-if="item.taskType == '3'">
                <information :ref="($event) => setItemRef($event, item.taskCode)"></information>
              </view>
              <view v-if="item.taskType == '2' || item.taskType == '12'">
                <sampleAnalysisze
                  :ref="($event) => setItemRef($event, item.taskCode)"
                ></sampleAnalysisze>
              </view>
              <view v-if="item.taskType == '4'">
                <questionForm :ref="($event) => setItemRef($event, item.taskCode)"></questionForm>
              </view>
              <view v-if="item.taskType == '9'">
                <otherForm :ref="($event) => setItemRef($event, item.taskCode)"></otherForm>
              </view>
              <view v-if="item.taskType == '6'">
                <fupeiForm :ref="($event) => setItemRef($event, item.taskCode)"></fupeiForm>
              </view>
              <view v-if="item.taskType == '7'">
                <attenuationForm
                  :ref="($event) => setItemRef($event, item.taskCode)"
                ></attenuationForm>
              </view>
              <view v-if="item.taskType == '30'">
                <directSampleForm
                  :ref="($event) => setItemRef($event, item.taskCode)"
                ></directSampleForm>
              </view>
              <view v-if="item.taskType == '13'">
                <extendenWarrantyPeriodForm
                  :ref="($event) => setItemRef($event, item.taskCode)"
                ></extendenWarrantyPeriodForm>
              </view>
            </view>
          </wd-collapse-item>
        </wd-collapse>
      </th-card>

      <th-card title="任务单信息">
        <!-- <th-form> -->

        <!-- <th-form-item label="任务编码">
          <text class="text">{{ form.projectCode }}</text>
        </th-form-item> -->
        <th-form-item label="任务名称">
          <!-- <text class="text">{{ form.projectName }}</text> -->
          <text class="text">{{ form.invName }}-{{ form.invStd }}-{{ form.projectName }}</text>
        </th-form-item>
        <!-- <th-form-item label="项目负责人">
          <text class="text">{{ form.projectHeadName }}</text>
        </th-form-item> -->
        <th-form-item label="任务预计完成日期" v-if="form.userTime">
          <!-- <text class="text">{{ formatByDayjs(form.userTime) }}</text> -->
          <text class="text">{{ formatByDayjs(form.userTime) }}</text>
        </th-form-item>
        <!-- <th-form-item label="技术负责人">
          <text class="text">{{ form.technologyHeadName }}</text>
        </th-form-item> -->
        <th-form-item label="任务负责人" v-if="form.technologyHeadName">
          <text class="text">{{ form.technologyHeadName }}</text>
        </th-form-item>
        <th-form-item label="任务成员" v-if="form.taskUser">
          <text class="text">{{ form.taskUser }}</text>
        </th-form-item>

        <th-form-item label="研发方案" class="form-demandDesc" v-if="form.rdPlan">
          <text class="text">{{ form.rdPlan }}</text>
        </th-form-item>
        <!-- <th-form-item label="项目成员">
          <text class="text">{{ form.rdProjectUser }}</text>
        </th-form-item>
        <th-form-item label="签收人">
          <text class="text">{{ form.signedName }}</text>
        </th-form-item> -->

        <!-- v-for="item in rdProjectUserList.filter(
            (item) => item.chooseFlag == 1 && item.documentsPostCode != '0',
          )" -->

        <!-- <th-form-item label="项目成员" class="form-demandDesc">
          <text class="text">{{ getProjectName({ documentsPostCode: 0 }) }}</text>
        </th-form-item> -->
        <!-- <th-form-item
          label="资料收集"
          style="flex-direction: column; align-items: start"
          v-if="form.rdInformationDTO && form.rdInformationDTO.length"
        >
          <view class="info-list">
            <view v-for="item in form.rdInformationDTO" :key="item.id" class="info-list-main">
              <view class="info-list-row">
                <view class="info-list-label">资料名称</view>
                <view class="info-list-value">{{ item.informationName }}</view>
              </view>
              <view class="info-list-row">
                <view class="info-list-label">资料描述</view>
                <view class="info-list-value">{{ item.informationDesc }}</view>
              </view>
              <view
                class="info-list-row"
                v-if="item.rdInformationProfileEntity && item.rdInformationProfileEntity.length"
              >
                <view class="info-list-label">附件</view>
                <view class="info-list-value">
                  <view style="display: flex; flex-direction: column">
                    <view
                      v-for="file in item.rdInformationProfileEntity"
                      :key="file.id"
                      @click="previewFileHandle(file.profileUrl)"
                      class="info-row-item"
                    >
                      {{ file.profileInfo }}
                    </view>
                  </view>
                </view>
              </view>
              <view class="info-list-row">
                <view class="info-list-label">网址</view>
                <view
                  class="info-list-value info-row-item"
                  @click="previewWeb(item.informationWeb)"
                >
                  {{ item.informationWeb }}
                </view>
              </view>
            </view>
          </view>
        </th-form-item> -->
        <th-form-item
          label="资料收集"
          style="flex-direction: column; align-items: start"
          v-if="
            form.rdInformationDTO && form.rdInformationDTO.length && taskTypeList.includes('10')
          "
        >
          <view class="info-list">
            <view v-for="item in form.rdInformationDTO" :key="item.id" class="info-list-main">
              <view class="info-list-row">
                <view class="info-list-label">资料名称</view>
                <view class="info-list-value">{{ item.informationName }}</view>
              </view>
              <view class="info-list-row">
                <view class="info-list-label">资料描述</view>
                <view class="info-list-value">{{ item.informationDesc }}</view>
              </view>
              <view
                class="info-list-row"
                v-if="item.rdInformationProfileEntity && item.rdInformationProfileEntity.length"
              >
                <view class="info-list-label">附件</view>
                <view
                  class="info-list-value"
                  style="flex-direction: column; align-items: flex-start"
                >
                  <view
                    v-for="file in item.rdInformationProfileEntity"
                    :key="file.id"
                    @click="previewFileHandle(file.profileUrl)"
                    class="info-row-item"
                  >
                    {{ file.profileInfo }}
                  </view>
                </view>
              </view>
              <view class="info-list-row">
                <view class="info-list-label">网址</view>
                <view
                  class="info-list-value info-row-item"
                  @click="previewWeb(item.informationWeb)"
                >
                  {{ item.informationWeb }}
                </view>
              </view>
            </view>
          </view>
        </th-form-item>
        <th-form-item
          label="资料收集综述"
          class="form-demandDesc"
          v-if="form.sampleReviewConclusion && taskTypeList.includes('10')"
        >
          <text class="text">{{ form.sampleReviewConclusion }}</text>
        </th-form-item>
        <th-form-item
          label="合成工艺路线"
          style="flex-direction: column; align-items: start"
          v-if="form.rdCraftEntity && form.rdCraftEntity.length && taskTypeList.includes('10')"
        >
          <view class="info-list">
            <view v-for="item in form.rdCraftEntity" :key="item.id" class="info-list-main">
              <view class="info-list-row">
                <view class="info-list-label">名称</view>
                <view class="info-list-value">{{ item.craftName }}</view>
                <view v-if="item.delFlag == 1">
                  <wd-tag plain bg-color="red" color="red">废弃</wd-tag>
                </view>
              </view>

              <view class="info-list-row">
                <view class="info-list-label">反应条件</view>
                <view class="info-list-value">{{ item.craftDesc }}</view>
              </view>

              <view class="info-list-row" v-if="item.craftUrl">
                <view class="info-list-label">路线</view>
                <view class="info-list-value">
                  <wd-img
                    :width="140"
                    :height="140"
                    :src="item.craftUrl"
                    mode="aspectFit"
                    :enable-preview="true"
                  />
                </view>
              </view>

              <view class="info-list-row">
                <view class="info-list-label">是否选择</view>
                <view class="info-list-value">
                  <wd-switch
                    disabled
                    v-model="item.isUse"
                    :active-value="1"
                    :inactive-value="0"
                    style="margin: 5rpx 0"
                    size="small"
                  ></wd-switch>
                </view>
              </view>
            </view>
          </view>
        </th-form-item>

        <th-form-item
          label="分析手段"
          v-if="
            (form.taskType == '10' || form.taskType == '11') &&
            form.rdSampleAnalysisQcEntity &&
            form.rdSampleAnalysisQcEntity.length
          "
        >
          <text class="text">
            <view style="display: flex; flex-wrap: wrap">
              <view
                v-for="item in form.rdSampleAnalysisQcEntity"
                :key="item.id"
                class="result-tag"
                style="margin-right: 10rpx; background-color: #4d80f0"
              >
                {{ item.analysisName }}
              </view>
            </view>
          </text>
        </th-form-item>
        <view
          style="overflow: auto"
          class="table-container"
          v-if="
            (form.taskType == '10' || form.taskType == '11') &&
            form.rdSampleAnalysisQcEntity &&
            form.rdSampleAnalysisQcEntity.length
          "
        >
          <table class="analysis-table">
            <tbody>
              <tr>
                <th style="width: 320rpx; min-width: 9.5rem">名称</th>
                <th style="width: 280rpx; min-width: 280rpx">说明</th>
              </tr>
              <tr
                align="center"
                v-for="(item, index) in form.rdSampleAnalysisQcEntity"
                :key="index"
              >
                <td>
                  <view>
                    {{ item.analysisName }}
                  </view>
                </td>
                <td>
                  <view>
                    {{ item.analysisDesc }}
                  </view>
                </td>
              </tr>
            </tbody>
          </table>
        </view>

        <th-form-item
          label="附件"
          style="flex-direction: column; align-items: start"
          v-if="
            form.rdTaskFileEntity && form.rdTaskFileEntity.length && taskTypeList.includes('10')
          "
        >
          <view class="info-list">
            <view class="info-list-main">
              <view class="info-list-row">
                <!-- <view class="info-list-label">附件</view> -->
                <view class="info-list-value">
                  <view style="display: flex; flex-direction: column">
                    <view
                      v-for="file in form.rdTaskFileEntity"
                      :key="file.id"
                      @click="previewFileHandle(file.fileUrl)"
                      class="info-row-item"
                    >
                      {{ file.fileName }}
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </th-form-item>

        <!-- 
        <template v-if="form.taskType == '2'">
          <th-form-item
            label="分析手段"
            v-if="form.rdSampleAnalysisEntity && form.rdSampleAnalysisEntity.length"
          >
            <text class="text">
              <view style="display: flex; flex-wrap: wrap">
                <view
                  v-for="item in form.rdSampleAnalysisEntity"
                  :key="item.id"
                  class="result-tag"
                  style="margin-right: 10rpx; background-color: #4d80f0"
                >
                  {{ item.analysisName }}
                </view>
              </view>
            </text>
          </th-form-item>
          <view
            style="overflow: auto"
            class="table-container"
            v-if="form.rdSampleAnalysisEntity && form.rdSampleAnalysisEntity.length"
          >
            <table class="analysis-table">
              <tbody>
                <tr>
                  <th style="width: 320rpx; min-width: 9.5rem">名称</th>
                  <th style="width: 280rpx; min-width: 280rpx">说明</th>
                </tr>
                <tr
                  align="center"
                  v-for="(item, index) in form.rdSampleAnalysisEntity"
                  :key="index"
                >
                  <td>
                    <view>
                      {{ item.analysisName }}
                    </view>
                  </td>
                  <td>
                    <view>
                      {{ item.analysisDesc }}
                    </view>
                  </td>
                </tr>
              </tbody>
            </table>
          </view>
          <th-card title="外来样报检报告">
            <assayReport :pid="form.id" :version="1"></assayReport>
          </th-card>
        </template> -->

        <!-- <th-form-item label="综述" class="form-demandDesc" v-if="form.sampleReviewConclusion">
          <text class="text">{{ form.sampleReviewConclusion }}</text>
        </th-form-item> -->

        <!-- <th-form-item label="其他内容" class="form-demandDesc" v-if="form.others">
          <text class="text">{{ form.others }}</text>
        </th-form-item> -->
        <!-- <th-form-item
          label="调查问卷"
          style="flex-direction: column; align-items: start"
          v-if="form.rdTaskFileEntity && form.rdTaskFileEntity.length"
        >
          <view class="info-list">
            <view class="info-list-main">
              <view class="info-list-row">
                <view class="info-list-label">附件</view>
                <view class="info-list-value">
                  <view style="display: flex; flex-direction: column">
                    <view
                      v-for="file in form.rdTaskFileEntity"
                      :key="file.id"
                      @click="previewFileHandle(file.fileUrl)"
                      class="info-row-item"
                    >
                      {{ file.fileName }}
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </th-form-item> -->
        <th-form-item label="下一步任务" class="form-demandDesc" v-if="form.wayName">
          <text class="text">{{ form.wayName }}</text>
        </th-form-item>

        <th-form-item
          label="分析手段"
          v-if="form.rdSampleAnalysisEntityNext && form.rdSampleAnalysisEntityNext.length"
        >
          <text class="text">
            <view style="display: flex; flex-wrap: wrap">
              <view
                v-for="item in form.rdSampleAnalysisEntityNext"
                :key="item.id"
                class="result-tag"
                style="margin-right: 10rpx; background-color: #4d80f0"
              >
                {{ item.analysisName }}
              </view>
            </view>
          </text>
        </th-form-item>
        <view
          style="overflow: auto"
          class="table-container"
          v-if="form.rdSampleAnalysisEntityNext && form.rdSampleAnalysisEntityNext.length"
        >
          <table class="analysis-table">
            <tbody>
              <tr>
                <th style="width: 320rpx; min-width: 9.5rem">名称</th>
                <th style="width: 280rpx; min-width: 280rpx">说明</th>
              </tr>
              <tr
                align="center"
                v-for="(item, index) in form.rdSampleAnalysisEntityNext"
                :key="index"
              >
                <td>
                  <view>
                    {{ item.analysisName }}
                  </view>
                </td>
                <td>
                  <view>
                    {{ item.analysisDesc }}
                  </view>
                </td>
              </tr>
            </tbody>
          </table>
        </view>

        <!-- <th-form-item label="评审结果">
          <text class="text">
            <view v-if="form.rdFlag == '1'" class="result-tag">通过</view>
            <view v-else-if="form.rdFlag == '0'" class="result-tag" style="background-color: #f50">
              不通过
            </view>
          </text>
        </th-form-item> -->
        <th-form-item label="评审结论" class="form-demandDesc" v-if="form.reviewConclusion">
          <text class="text">{{ form.reviewConclusion }}</text>
        </th-form-item>
        <th-form-item label="评审结论描述" class="form-demandDesc" v-if="form.requirements">
          <text class="text">{{ form.requirements }}</text>
        </th-form-item>

        <th-form-item label="需求回复" class="form-demandDesc" v-if="form.reply">
          <text class="text">{{ form.reply }}</text>
        </th-form-item>
        <th-form-item label="需求反馈方式" class="form-demandDesc" v-if="form.replyNeed != 3">
          <text class="text">
            <!-- {{ form.replyNeed == 1 ? '回复' : form.replyNeed == 0 ? '不回复' : '' }} -->
            {{ getReplyNeed(form.replyNeed) }}
          </text>
        </th-form-item>
        <th-form-item
          label="是否可用"
          class="form-demandDesc"
          v-if="form.useFlag != null && cusFlagDemand == '3'"
        >
          <text class="text">
            {{ form.useFlag == '1' ? '可用' : form.useFlag == '0' ? '不可用' : '' }}
          </text>
        </th-form-item>
        <th-form-item
          label="需求回复附件"
          class="form-demandDesc"
          v-if="form.rdReviewFileEntity && form.rdReviewFileEntity.length"
        >
          <view class="info-list">
            <view
              class="info-list-main"
              style="padding-top: 0; padding-left: 0; margin-top: 0; border: none"
            >
              <view class="info-list-row">
                <!-- <view class="info-list-label">附件</view> -->
                <view class="info-list-value">
                  <view style="display: flex; flex-direction: column">
                    <view
                      v-for="file in form.rdReviewFileEntity"
                      :key="file.id"
                      @click="previewFileHandle(file.fileUrl)"
                      class="info-row-item"
                    >
                      {{ file.fileName }}
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </th-form-item>
        <th-form-item label="是否立项" class="form-demandDesc" v-if="form.taskPetitionId">
          <text class="text">
            {{ form.petitionFlag == 1 ? '立项' : form.petitionFlag == 0 ? '不立项' : '' }}
          </text>
        </th-form-item>
        <th-form-item
          label="项目名称"
          class="form-demandDesc"
          v-if="form.taskPetitionId && form.petitionFlag == 1"
        >
          {{ form.petitionName }}
        </th-form-item>
        <th-form-item
          label="是否推荐现有产品"
          class="form-demandDesc"
          v-if="form.wayCode == '30' && form.recommendFlag !== null"
        >
          <text class="text">
            {{ form.recommendFlag == 1 ? '是' : form.recommendFlag == 0 ? '否' : '' }}
          </text>
        </th-form-item>
        <th-form-item label="推荐产品名称" class="form-demandDesc" v-if="form.recommendFlag == 1">
          <text class="text">
            {{ form.recommendInvName }}
          </text>
        </th-form-item>
        <th-form-item label="推荐产品规格" class="form-demandDesc" v-if="form.recommendFlag == 1">
          <text class="text">
            {{ form.recommendInvStd }}
          </text>
        </th-form-item>

        <template v-if="showMoreTask">
          <th-form-item label="任务单编号">
            <text class="text">{{ form.taskCode }}</text>
          </th-form-item>
          <th-form-item
            v-for="item in rdProjectUserList.filter(
              (item) => item.chooseFlag == 1 && item.mainFlag == '1',
            )"
            :label="item.documentsPostName"
            :key="item.id"
          >
            <text class="text">{{ getProjectName(item, 0, false) }}</text>
          </th-form-item>
        </template>
        <view class="exportModel" @click="showMoreTaskhandle">
          <text>{{ showMoreTask ? '收起' : '展开' }}</text>
        </view>
        <!-- </th-form> -->
      </th-card>

      <!-- <th-card :title="form.projectName" v-if="form.taskType == 30">
        <directSampleForm ref="directSampleFormRef"></directSampleForm>
      </th-card> -->

      <template v-if="form.taskType == 30">
        <directSampleForm ref="directSampleFormRef"></directSampleForm>
      </template>

      <th-card :title="form.projectName" v-if="form.taskType == 9">
        <otherForm ref="otherFormRef"></otherForm>
      </th-card>

      <th-card :title="form.projectName" v-if="form.taskType == 4">
        <questionForm ref="questionFormRef"></questionForm>
      </th-card>

      <th-card
        :title="form.projectName"
        v-if="
          (form.taskType == 2 || form.taskType == 12) &&
          form.rdSampleAnalysisEntity &&
          form.rdSampleAnalysisEntity.length
        "
      >
        <th-form-item
          label="分析手段"
          v-if="form.rdSampleAnalysisEntity && form.rdSampleAnalysisEntity.length"
        >
          <text class="text">
            <view style="display: flex; flex-wrap: wrap">
              <view
                v-for="item in form.rdSampleAnalysisEntity"
                :key="item.id"
                class="result-tag"
                style="margin-right: 10rpx; background-color: #4d80f0"
              >
                {{ item.analysisName }}
              </view>
            </view>
          </text>
        </th-form-item>
        <view
          style="overflow: auto"
          class="table-container"
          v-if="form.rdSampleAnalysisEntity && form.rdSampleAnalysisEntity.length"
        >
          <table class="analysis-table">
            <tbody>
              <tr>
                <th style="width: 320rpx; min-width: 9.5rem">名称</th>
                <th style="width: 280rpx; min-width: 280rpx">说明</th>
              </tr>
              <tr align="center" v-for="(item, index) in form.rdSampleAnalysisEntity" :key="index">
                <td>
                  <view>
                    {{ item.analysisName }}
                  </view>
                </td>
                <td>
                  <view>
                    {{ item.analysisDesc }}
                  </view>
                </td>
              </tr>
            </tbody>
          </table>
        </view>
        <!-- <th-card title="外来样报检报告">
          <assayReport :pid="form.id" :version="1"></assayReport>
        </th-card> -->
      </th-card>

      <template v-if="form.taskType == 2 || form.taskType == 12">
        <assayReport :pid="form.id" :version="1"></assayReport>
        <th-card title="附件" v-if="form.rdTaskFileEntity && form.rdTaskFileEntity.length">
          <view class="info-list">
            <view class="info-list-main">
              <view class="info-list-row">
                <!-- <view class="info-list-label">附件</view> -->
                <view class="info-list-value">
                  <view style="display: flex; flex-direction: column">
                    <view
                      v-for="file in form.rdTaskFileEntity"
                      :key="file.id"
                      @click="previewFileHandle(file.fileUrl)"
                      class="info-row-item"
                    >
                      {{ file.fileName }}
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </th-card>
      </template>

      <!-- <th-card :title="form.projectName" v-if="form.taskType == 3">
        <information ref="informationRef"></information>
      </th-card> -->

      <th-card :title="form.projectName" v-if="form.taskType == 13">
        <extendenWarrantyPeriodForm
          ref="extendenWarrantyPeriodFormRef"
        ></extendenWarrantyPeriodForm>
      </th-card>

      <template v-if="form.taskType == 3">
        <information ref="informationRef"></information>
      </template>
      <template v-if="form.taskType == 6">
        <fupeiForm ref="fupeiFormRef"></fupeiForm>
      </template>
      <template v-if="form.taskType == 7">
        <attenuationForm ref="attenuationFormRef"></attenuationForm>
      </template>

      <!-- <th-card title="评审建议" v-if="demandOpinionUserName == '2006031401' || form.taskOpinion">
        <view style="width: 100%">
          <view
            v-if="
              !(
                form.reviewStatus != 2 &&
                form.taskAllStatus == 1 &&
                demandOpinionUserName == '2006031401'
              )
            "
            class="form-demandDesc"
          >
            <text class="text">
              {{ form.taskOpinion }}
            </text>
          </view>
          <view v-else>
            <wd-textarea
              v-model="form.taskOpinion"
              placeholder="请填写评审建议"
              auto-height
              :maxlength="2000"
              show-word-limit
              no-border
              prop="taskOpinion"
              :disabled="
                !(
                  form.reviewStatus != 2 &&
                  form.taskAllStatus == 1 &&
                  demandOpinionUserName == '2006031401'
                )
              "
            />
          </view>
        </view>
        <wd-button
          :round="false"
          style="width: 100%; margin-top: 20rpx"
          @click="saveDemandOpinion"
          v-if="
            form.reviewStatus != 2 &&
            form.taskAllStatus == 1 &&
            demandOpinionUserName == '2006031401'
          "
        >
          保存
        </wd-button>
      </th-card> -->

      <th-card
        title="评审意见"
        v-if="
          (opinionList && opinionList.length) || (form.reviewStatus != 2 && form.taskAllStatus == 1)
        "
      >
        <view style="width: 100%">
          <view
            style="overflow: auto"
            class="table-container"
            v-if="opinionList && opinionList.length"
          >
            <table class="analysis-table">
              <tbody>
                <tr>
                  <th style="width: 100rpx; min-width: 100rpx">姓名</th>
                  <th style="width: 280rpx; min-width: 280rpx">评审意见</th>
                </tr>
                <tr align="center" v-for="(item, index) in opinionList" :key="index">
                  <td>
                    <view>
                      {{ item.createName }}
                    </view>
                  </td>
                  <td>
                    <view>
                      {{ item.reviewOpinion }}
                    </view>
                  </td>
                </tr>
              </tbody>
            </table>
          </view>
          <view v-if="form.reviewStatus != 2 && form.taskAllStatus == 1">
            <wd-textarea
              v-model="opinionParasm.reviewOpinion"
              placeholder="请填写评审意见"
              auto-height
              :maxlength="2000"
              show-word-limit
              no-border
              prop="reviewOpinion"
              style="min-height: 200rpx"
              :disabled="!(form.reviewStatus != 2 && form.taskAllStatus == 1)"
            />
          </view>
        </view>
        <wd-button
          :round="false"
          style="width: 100%; margin-top: 20rpx"
          @click="saveDemandOpinion"
          v-if="form.reviewStatus != 2 && form.taskAllStatus == 1"
        >
          保存
        </wd-button>
      </th-card>

      <th-card title="评审人员签字">
        <th-form>
          <!-- <th-form-item label="副总工">
            <wd-img
              :width="200"
              :height="100"
              :src="form.deputyChiefEngineerUrl"
              @click="preview(form.deputyChiefEngineerUrl)"
            />
          </th-form-item>
          <th-form-item label="总工">
            <wd-img
              :width="200"
              :height="100"
              :src="form.chiefEngineerUrl"
              @click="preview(form.chiefEngineerUrl)"
            />
          </th-form-item> -->
          <!-- v-for="item in rdProjectUserList.filter((item) => item.chooseFlag == 0)" -->
          <th-form-item
            v-for="item in form.rdProjectUserEntity.filter((item) => item.signatureFlag == 1)"
            :label="item.documentsPostName"
          >
            <!-- @click="preview(getProjectName(item, 1))" -->
            <wd-img :width="200" :height="100" :src="getProjectName(item, 1)" />
          </th-form-item>
          <th-form-item
            v-for="item in form.rdProjectUserEntity.filter(
              (item) => item.documentsPostCode == '255' && item.userUrl,
            )"
            :label="item.documentsPostName"
          >
            <!-- @click="preview(getProjectName(item, 1))" -->
            <wd-img :width="200" :height="100" :src="getProjectName(item, 1)" />
          </th-form-item>
        </th-form>
      </th-card>

      <!-- <view class="sign-main bg-white" @click="sign" v-if="showSign">
        签字
      </view> -->
      <view :class="['sign-main', 'bg-white']" @click="sign" v-if="showSignProject">签字</view>
    </view>

    <wd-action-sheet v-model="showAction" title="" @close="closeSign" @click-modal="closeSign">
      <view class="sign-main-show">
        <!-- <text class="sign-main-show-title">签字</text> -->
        <view class="sign-main-show-line">
          <!-- <wd-img :width="200" :height="100" :src="signature" @click="preview(signature)" /> -->
          <wd-img :width="200" :height="100" :src="signature" @click="signThis" />
        </view>
        <!-- <view class="sign-main-show-btn" @click="signThis">使用该签字</view> -->
        <view class="sign-main-show-btn" @click="signReset">重新签字</view>
      </view>
    </wd-action-sheet>
  </view>
</template>

<script lang="ts" setup>
import { useSetting } from '@/stores/setting';
import {
  getObj,
  getPersonByPersonCode,
  updateByIdEvery,
  uploadSignature,
  updateByIdOpinion,
} from '@/service/pm-task';
import { formatByDayjs } from '@/utils/util';
import { useUserStore } from '@/stores/user';
import {
  selectrdDocumentsPostUser,
  selectrdDocumentsPostDict,
  updateSignHandle,
  saveOpinion,
  updateOpinion,
  getOpinion,
} from '@/service/pm-requirement';
import information from './component/information.vue';
import sampleAnalysisze from './component/sample-analysize.vue';
import questionForm from './component/question.vue';
import otherForm from './component/other.vue';
import attenuationForm from './component/attenuation.vue';
import directSampleForm from './component/direct-sample.vue';
// import assayReport from '@/pages/pm/assay-report/component/assayReport.vue';
import assayReport from './component/assayReport.vue';
import fupeiForm from './component/fupei.vue';
import extendenWarrantyPeriodForm from './component/extenden-warranty-period-form.vue';

const setting = useSetting();
const userStore = useUserStore();
const showSign = ref(false);
const signature = ref('');
const userInfo = ref({});
const isChiefEngineer = ref('');
const isDeputyChiefEngineer = ref('');
const showAction = ref(false);
const postUserObj: any = ref({});
const rdProjectUserList = ref([]); // 签名列表
const showSignProject = ref(false);
const directSampleFormRef: any = ref({});
const otherFormRef: any = ref({});
const questionFormRef: any = ref({});
const informationRef: any = ref({});
const checkTargetList = ref([]);
const demandOpinionUserName = ref('');
const fupeiFormRef: any = ref({});
const attenuationFormRef: any = ref({});
const extendenWarrantyPeriodFormRef: any = ref({});

// 提交表单数据
const form = reactive({
  id: null,
  demandDate: null,
  personName: null,
  demandType: null,
  deptHead: null,
  deptCode: null,
  applicationType: null,
  samplesNum: null,
  demandDesc: null,
  sampleCoding: null,
  askCompleteTime: null,
  taskCode: null,
  userCode: null,
  invName: null,
  invDemand: null,
  sampleFlag: null,
  demandCode: null,
  demandTypeCode: null,
  cusName: null,
  personCode: null,
  deptHeadCode: null,
  cusFlag: '0',
  demandResult: null,
  completeTime: null,
  // technologyHead: null,
  remark: null,
  // technologyHeadCode: null,
  taskId: null,
  instanceId: null,
  invStd: null,
  sampleCode: null,
  sampleBatch: null,
  deptName: null,
  rdFlag: null,
  chiefEngineer: null,
  deputyChiefEngineer: null,
  status: null,
  sampleFlagName: null,
  deputyChiefEngineerUrl: null,
  chiefEngineerUrl: null,
  sampleUnit: null,
  cusCode: null,
  projectCode: null,
  projectName: null,
  rdProjectUser: null,
  projectHead: null,
  userTime: null,
  // technologyHeadName: null,
  rdInformationDTO: [],
  rdCraftEntity: [],
  rdSampleAnalysisEntity: [],
  rdPlan: null,
  sampleReviewConclusion: null,
  requirements: null,
  projectHeadName: null,
  signedName: null,
  rdProjectUserEntity: [],
  rdTaskListAll: [],
  rdTaskFileEntity: [],
  others: null,
  wayName: null,
  rdSampleAnalysisEntityNext: [],
  taskType: null,
  reply: '',
  requestFlag: '0',
  requestNum: '',
  requestNumUnit: '',
  rdDemandFileEntity: [],
  taskOpinion: '',
  petitionFlag: null,
  petitionName: null,
  recommendFlag: null,
  recommendInvName: null,
  recommendInvStd: null,
  reviewConclusion: null,
  taskPetitionId: null,
  rdReviewFileEntity: null,
  replyNeed: null,
  rdSampleAnalysisQcEntity: [],
  useFlag: null,
});

const cusFlagDemand = ref('');
const init = (params) => {
  uni.$off('pm-requirement-sign');
  selectrdDocumentsPostDictList();
  uni.showLoading();
  console.log('------');
  getObj(params)
    .then((res) => {
      console.log('res', res);
      Object.assign(form, res.data);
      const { rdDemandEntity } = res.data;
      if (rdDemandEntity) {
        const o: any = {};
        o.demandDate = rdDemandEntity.demandDate ? formatByDayjs(rdDemandEntity.demandDate) : '';
        o.askCompleteTime = rdDemandEntity.askCompleteTime
          ? formatByDayjs(rdDemandEntity.askCompleteTime)
          : '';
        o.demandCode = rdDemandEntity.demandCode;
        o.cusCode = rdDemandEntity.cusCode;
        o.deptName = rdDemandEntity.deptName;
        o.demandType = rdDemandEntity.demandType;
        o.deptCode = rdDemandEntity.deptCode;
        o.invName = rdDemandEntity.invName;
        o.invStd = rdDemandEntity.invStd;
        o.applicationType = rdDemandEntity.applicationType;
        o.invDemand = rdDemandEntity.invDemand;
        o.sampleFlagName = rdDemandEntity.sampleFlagName;
        o.sampleCode = rdDemandEntity.sampleCode;
        o.samplesNum = rdDemandEntity.samplesNum;
        o.sampleUnit = rdDemandEntity.sampleUnit;
        o.sampleBatch = rdDemandEntity.sampleBatch;
        // o.askCompleteTime = rdDemandEntity.askCompleteTime;
        o.demandDesc = rdDemandEntity.demandDesc;
        o.cusFlag = rdDemandEntity.cusFlag;
        o.sampleFlag = rdDemandEntity.sampleFlag;
        o.personName = rdDemandEntity.personName;

        o.requestFlag = rdDemandEntity.requestFlag;
        o.requestNum = rdDemandEntity.requestNum;
        o.requestNumUnit = rdDemandEntity.requestNumUnit;
        o.demandResult = rdDemandEntity.demandResult;
        // o.cusName = rdDemandEntity.cusName;
        o.demandTypeCode = rdDemandEntity.demandTypeCode;
        o.reviewConclusiondemand = rdDemandEntity.reviewConclusion;
        cusFlagDemand.value = rdDemandEntity.cusFlag;

        o.tenantName = rdDemandEntity.tenantName;
        checkTargetList.value = res.data.rdDemandStandardEntity
          .filter((item) => item.delFlag != 1)
          .map((item) => {
            return {
              ...item,
              standardName: item.standardName,
              standardCode: item.standardCode,
              standardValue: item.standardValue,
              standardValuePm: item.standardValuePm,
            };
          });

        Object.assign(form, o);
      }

      // analysisList.value = res.data.rdSampleAnalysisEntity;
      // const rdProject = [];
      const rdProject = [];
      res.data.rdProjectUserEntity.forEach((item: any) => {
        rdProject.push(item.userName);
      });
      form.rdProjectUser = rdProject.join(',');

      let rdInformationDTO =
        res.data.rdInformationDTO && res.data.rdInformationDTO.length
          ? res.data.rdInformationDTO
          : [];
      rdInformationDTO = rdInformationDTO.map((item) => {
        const l = item.rdInformationProfileEntity;
        const rdInformationProfileEntity = [];
        l.forEach((rd) => {
          const { profileType } = rd;
          if (profileType == 'web') {
            item.informationWeb = rd.profileUrl;
          } else {
            rdInformationProfileEntity.push(rd);
          }
        });

        return {
          ...item,
          rdInformationProfileEntity,
        };
      });

      form.rdInformationDTO = rdInformationDTO;
      const v = String(res.data.taskType);
      taskTypeList.value = [v];

      form.rdTaskListAll =
        form.rdTaskListAll && form.rdTaskListAll.length ? form.rdTaskListAll : [];
      form.rdTaskListAll = form.rdTaskListAll.map((item) => {
        return {
          ...item,
          title: `${item.taskCode} - ${item.projectName}`,
        };
      });

      // 判断能不能签字
      const { userInfos } = userStore;
      const cusPerson = userInfos.user.username;
      demandOpinionUserName.value = cusPerson;
      const o = form.rdProjectUserEntity.find((item) => item.userCode == cusPerson);
      if (o) {
        showSignProject.value = true;
      } else {
        showSignProject.value = false;
      }
      if (form.taskType == '30') {
        nextTick(() => {
          directSampleFormRef.value.init(res.data);
        });
      } else if (form.taskType == '9') {
        nextTick(() => {
          otherFormRef.value.init(res.data);
        });
      } else if (form.taskType == '4') {
        nextTick(() => {
          questionFormRef.value.init(res.data);
        });
      } else if (form.taskType == '3') {
        nextTick(() => {
          informationRef.value.init(res.data);
        });
      } else if (form.taskType == '6') {
        nextTick(() => {
          fupeiFormRef.value.init(res.data);
        });
      } else if (form.taskType == '7') {
        nextTick(() => {
          attenuationFormRef.value.init(res.data);
        });
      } else if (form.taskType == '13') {
        nextTick(() => {
          extendenWarrantyPeriodFormRef.value.init(res.data);
        });
      }
      rdReviewOpinionHandle();
    })
    .finally(() => {
      uni.stopPullDownRefresh();
      uni.hideLoading();
    })
    .catch((err) => {
      console.log('err', err);
    });
  // checkPost();
  selectrdDocumentsPostUserFn();
};

onLoad((options) => {
  const { params } = options;
  let obj = {};

  if (params) {
    obj = JSON.parse(params);
  } else {
    obj = options;
  }

  init({
    id: obj.id,
    taskCode: obj.taskCode,
    demandCode: obj.demandCode,
  });
});

const getRdFlat = (flag) => {
  if (flag == '1') {
    return '通过';
  }
  if (flag == '0') {
    return '不通过';
  }
};

const checkPost = () => {
  // 获取用户的岗位 和签字
  // getPersonByPersonCode
  const { userInfos } = userStore;
  const cusPerson = userInfos.user.username;
  getPersonByPersonCode({
    personCode: cusPerson,
  }).then((res) => {
    const sign = res.data.signature;
    signature.value = sign;
    const { hrPersonDeptList } = res.data;
    const postNameList = hrPersonDeptList.map((item) => item.postName); // 岗位列表
    // 判断是否有总工 、 副总工
    const _isChiefEngineer = postNameList.find(
      (item) => item && item.indexOf('副总工') < 0 && item.indexOf('总工') >= 0,
    );
    const _isDeputyChiefEngineer = postNameList.find((item) => item && item.indexOf('副总工') >= 0);
    isChiefEngineer.value = _isChiefEngineer;
    isDeputyChiefEngineer.value = _isDeputyChiefEngineer;
    if (_isChiefEngineer || _isDeputyChiefEngineer) {
      showSign.value = true;
    } else {
      showSign.value = false;
    }
    userInfo.value = res.data;
  });
};

const sign = () => {
  // uni.navigateTo({
  //   url: '/pages/pm/requirement/sign',
  // });

  // 判断能不能签字
  if (form.rdFlag == null) {
    uni.showToast({
      title: '没有评审结果，不允许签字',
      icon: 'none',
    });
    return;
  }

  // 判断签字
  const { userInfos } = userStore;
  const cusPerson = userInfos.user.username;
  getPersonByPersonCode({
    personCode: cusPerson,
  }).then((res) => {
    const sign = res.data.signature;
    signature.value = sign;
    userInfo.value = res.data;
    if (sign) {
      showAction.value = true;
    } else {
      uni.$on('pm-requirement-sign', (e) => {
        console.log('sign', e);
        signHanle(e);
      });
      uni.navigateTo({
        url: '/pages/pm/requirement/autograph',
      });
    }
  });

  // uni.navigateTo({
  //   url: '/pages/pm/requirement/autograph',
  // });
};

onPullDownRefresh(() => {
  init({
    id: form.id,
    taskCode: form.taskCode,
    demandCode: form.demandCode,
  });
});

const goBack = () => {
  uni.navigateBack();
};

const preview = (url) => {
  if (!url) return;
  uni.previewImage({
    urls: [url],
  });
};

const closeSign = () => {
  showAction.value = false;
  uni.$off('pm-requirement-sign');
};

const signHanle = (sign) => {
  const userInfos: any = userInfo.value;
  // // 判断岗位
  // const _isChiefEngineer = isChiefEngineer.value;
  // const _isDeputyChiefEngineer = isDeputyChiefEngineer.value;

  // const params = {
  //   id: form.id,
  // };

  // if (!_isChiefEngineer && !_isDeputyChiefEngineer) {
  //   uni.showToast({
  //     title: '只有总工和副总工才能签字',
  //     icon: 'none',
  //   });
  //   return;
  // }

  // if (_isChiefEngineer) {
  //   // params['chiefEngineer'] = userInfos.id;
  //   params['chiefEngineer'] = userInfos.personCode;
  //   params['chiefEngineerName'] = userInfos.personName;
  //   params['chiefEngineerPost'] = _isChiefEngineer;
  //   params['chiefEngineerUrl'] = sign;
  // } else if (_isDeputyChiefEngineer) {
  //   params['deputyChiefEngineer'] = userInfos.personCode;
  //   params['deputyChiefEngineerName'] = userInfos.personName;
  //   params['deputyChiefEngineerPost'] = _isDeputyChiefEngineer;
  //   params['deputyChiefEngineerUrl'] = sign;
  // }

  console.log('postUserObj', postUserObj.value);
  const params = {
    demandCode: form.demandCode,
    taskCode: form.taskCode,
    personId: userInfos.id,
    userName: userInfos.personName,
    userCode: userInfos.personCode,
    userUrl: sign,
    // userType: postUserObj.value.documentsPostCode,
    documentsPostName: postUserObj.value.documentsPostName,
    documentsPostCode: postUserObj.value.documentsPostCode,
    documentsName: postUserObj.value.documentsName,
    documentsCode: postUserObj.value.documentsCode,
    signatureFlag: postUserObj.value.signatureFlag,
    reviewFlag: postUserObj.value.reviewFlag,
    rdCode: form.taskCode,
  };

  uni.showLoading({
    mask: true,
  });

  updateSignHandle(params)
    .then((res) => {
      if (res.code == 0) {
        uni.showToast({
          title: '签字成功',
        });

        // setTimeout(() => {
        //   uni.navigateBack();
        // }, 500);

        // 更新签字
        if (!signature.value) {
          uploadSignature({
            id: userInfos.id,
            signature: sign,
          });
        }
        showAction.value = false;
        // 刷新页面
        init({
          id: form.id,
          taskCode: form.taskCode,
          demandCode: form.demandCode,
        });
      } else {
        uni.showToast({
          mask: true,
          title: `签字失败,原因${res.msg}`,
          icon: 'none',
        });
      }
    })
    .finally(() => {
      uni.hideLoading();
      // uni.$off('pm-requirement-sign');
      // saveDemandOpinion();
    });
};

const signThis = () => {
  const sign = signature.value;
  signHanle(sign);
};

const signReset = () => {
  uni.$on('pm-requirement-sign', (e) => {
    console.log('sign', e);
    signHanle(e);
  });
  uni.navigateTo({
    url: '/pages/pm/requirement/autograph',
  });
};

const previewImg = (url) => {
  if (!url) return;
  const urls = [];
  urls.push(url);
  console.log('url', urls);
  uni.previewImage({
    urls,
    fail: (fail) => {
      console.log('fail', fail);
    },
  });
};

const previewFileHandle = (file) => {
  uni.navigateTo({
    url: `/pages/pm/preview-online?url=${file}`,
  });
};

const previewWeb = (url) => {
  uni.navigateTo({
    url: `/pages/pm/preview-online?url=${url}&isWeb=1`,
  });
};

const selectrdDocumentsPostDictList = async () => {
  try {
    const res = await selectrdDocumentsPostDict({
      webSql: `documents_code = '2'`,
      size: 1000,
    });
    if (res.code !== 0) {
      return;
    }
    rdProjectUserList.value = res.data.records;
  } catch (err) {
    console.log('err', err);
  }
};

const selectrdDocumentsPostUserFn = () => {
  const { userInfos } = userStore;
  const cusPerson = userInfos.user.username;

  selectrdDocumentsPostUser({
    webSql: `user_code = '${cusPerson}' and documents_code = 2`,
    size: 1000,
  })
    .then((res) => {
      if (res.code == 0) {
        if (res.data.records.length) {
          const lrs = res.data.records.find(
            (item) => item.reviewFlag == 1 && item.signatureFlag == 1,
          );
          const lr = res.data.records.find((item) => item.reviewFlag == 1);
          const l = res.data.records;
          let o: any = {};

          if (lrs.length) {
            o = lrs[0];
          } else if (lr.length) {
            o = lr[0];
          } else {
            o = l[0];
          }
          postUserObj.value = o;
          if (o.reviewFlag == 1 || o.signatureFlag == 1) {
            showSign.value = true;
          } else {
            showSign.value = false;
          }
        } else {
          showSign.value = false;
        }
      } else {
        showSign.value = false;
      }
    })
    .catch(() => {
      showSign.value = false;
    });
};

// type 0 获取姓名 1 获取签名
const getProjectName = (item, type = 0, isShow = true) => {
  // const l = form.rdProjectUserEntity.filter((f) => f.userType == item.documentsPostCode);
  // const l = form.rdProjectUserEntity.filter(
  //   (f) => f.userCode == item.userCode && f.userType == item.documentsPostCode,
  // );
  let l = form.rdProjectUserEntity.filter(
    (f) => f.userCode == item.userCode && f.userType == item.documentsPostCode,
  );
  if (isShow) {
    l = form.rdProjectUserEntity.filter(
      (f) => f.userCode == item.userCode && f.userType == item.documentsPostCode,
    );
  } else {
    l = form.rdProjectUserEntity.filter((f) => f.userType == item.documentsPostCode);
  }
  console.log('lll', l);
  let s = '';
  if (l.length) {
    console.log('s', s);
    if (type == 0) {
      s = l.map((item) => item.userName).join(',');
      return s;
    }
    // s = l.map((item) => item.userUrl).join(',');
    s = l[0].userUrl;
    return s;
  }
  return s;
};

const taskTypeList = ref([]);
const rdTaskListAllActiveKey = ref([]);

const tableRefs = ref({});
const setItemRef = (e, item) => {
  tableRefs.value[item] = e;
};

const changeTaskAllList = (e) => {
  const vl = e.value;

  const last = vl[vl.length - 1];
  const o = form.rdTaskListAll.find((item) => item.id == last);
  if (!last) return;

  nextTick(() => {
    console.log(' tableRefs.value', tableRefs.value, o);

    try {
      uni.showLoading();
      getObj({ id: last })
        .then((res) => {
          if (res.code != 0) {
            uni.showToast({
              mask: true,
              title: `获取数据失败, 失败原因: ${res.msg}`,
              icon: 'none',
            });
            return;
          }
          tableRefs.value[o.taskCode].init(res.data);
        })
        .finally(() => {
          uni.hideLoading();
        });
    } catch (error) {
      console.log('err', error);
    }
  });
};

const beforeExpend = (e) => {
  return new Promise((reslove, reject) => {
    const o = form.rdTaskListAll.find((item) => item.id == e);
    try {
      uni.showLoading();
      getObj({ id: e })
        .then((res) => {
          if (res.code != 0) {
            uni.hideLoading();
            uni.showToast({
              mask: true,
              title: `获取数据失败, 失败原因: ${res.msg}`,
              icon: 'none',
            });
            return;
          }
          nextTick(() => {
            tableRefs.value[o.taskCode].init(res.data);
            // reslove(true);
            setTimeout(() => {
              uni.hideLoading();
              reslove(true);
            }, 1000);
          });
        })
        .catch((err) => {
          uni.hideLoading();
          console.log('nefore', err);
        });
    } catch (error) {
      console.log('err', error);
      reject(false);
    }
  });
};

const showMoreDemand = ref(false);
const showMoreDemandhandle = () => {
  showMoreDemand.value = !showMoreDemand.value;
};

// const saveDemandOpinion = () => {
//   uni.showLoading({
//     mask: true,
//   });
//   updateByIdOpinion({
//     id: form.id,
//     taskCode: form.taskCode,
//     taskOpinion: form.taskOpinion,
//   })
//     .then((res) => {
//       if (res.code != 0) {
//         uni.showToast({
//           title: res.msg,
//           icon: 'none',
//         });
//         return;
//       }
//       init({
//         id: form.id,
//         taskCode: form.taskCode,
//         demandCode: form.demandCode,
//       });
//     })
//     .finally(() => {
//       uni.hideLoading();
//     });
// };

const showMoreTask = ref(false);
const showMoreTaskhandle = () => {
  showMoreTask.value = !showMoreTask.value;
};

const opinionParasm = reactive({
  reviewOpinion: '',
  reviewType: 1,
  id: null,
});
const opinionList = ref([]);

const saveDemandOpinion = () => {
  const params = {
    ...opinionParasm,
    demandId: form.demandId,
    demandCode: form.demandCode,
    taskCode: form.taskCode,
    taskId: form.id,
  };
  uni.showLoading({
    mask: true,
  });
  (opinionParasm.id ? updateOpinion(params) : saveOpinion(params))
    .then((res) => {
      if (res.code != 0) {
        uni.showToast({
          title: res.msg,
          icon: 'none',
        });
        return;
      }
      init({
        id: form.id,
        taskCode: form.taskCode,
        demandCode: form.demandCode,
      });
    })
    .finally(() => {
      uni.hideLoading();
    });
};

const rdReviewOpinionHandle = () => {
  uni.showLoading({
    mask: true,
  });
  getOpinion({
    taskCode: form.taskCode,
  })
    .then((res) => {
      if (res.code != 0) {
        uni.showToast({
          mask: true,
          title: `获取数据失败，失败原因：${res.msg}`,
          icon: 'none',
        });
        return;
      }
      opinionList.value = res.data;
      const { userInfos } = userStore;
      const cusPerson = userInfos.user.username;
      const o = res.data.find((item) => item.createBy == cusPerson);
      if (o) {
        opinionParasm.reviewOpinion = o.reviewOpinion;
        opinionParasm.id = o.id;
      }
    })
    .finally(() => {
      uni.hideLoading();
    });
};

const getReplyNeed = (replyNeed) => {
  if (replyNeed == 3) return '';
  const replyList = [
    {
      label: '不反馈',
      value: 0,
    },
    {
      label: '直接反馈',
      value: 1,
    },
    {
      label: '总经理确认后反馈',
      value: 2,
    },
  ];

  const o = replyList.find((item) => item.value == replyNeed);
  return o ? o.label : '';
};
</script>

<style lang="scss" scoped>
@import '../experiment/components/table';

.block .content {
  padding: 0 !important;
}

.card-detail {
  padding: 0 !important;
}

.wd-cell {
  padding-left: 0 !important;
}

.wd-card__title {
  border-left: 4px solid #2e5cf6 !important;
}

.pm-table {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 0 30rpx;

  .pm-title {
    box-sizing: border-box;
    padding-left: 20rpx;
    margin: 40rpx 0;
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    border-left: 8rpx solid #2e5cf6;
    border-radius: 4rpx;
  }

  .pm-row {
    display: flex;
    min-height: 60rpx;
    border-bottom: 1px solid #f6f0f0;

    .pm-label {
      display: flex;
      align-items: center;
      width: 20%;
      font-size: 26rpx;
      color: #979494;
    }

    .pm-value {
      display: flex;
      flex: 1;
      align-items: center;
      font-size: 26rpx;
      color: #333;
    }
  }
}

.sign-main {
  position: fixed;
  right: 0rpx;
  bottom: 40rpx;

  // display: flex;
  // align-items: center;
  // justi fy-content: center;
  // width: 100%;
  // margin: 20rpx 0;
  width: 160rpx;
  height: 80rpx;
  line-height: 80rpx;
  color: white;
  text-align: center;
  background-color: rgb(77 128 240);

  // border-radius: 50%;
  border-top-left-radius: 40rpx;
  border-bottom-left-radius: 40rpx;
}

:deep(.label) {
  width: 160rpx !important;
}

.result-tag {
  padding: 6rpx 14rpx;
  margin: 2rpx 0;
  font-size: 24rpx;
  color: white;
  background-color: #87d068;
  border-radius: 4rpx;
}

.sign-main-show {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  .sign-main-show-title {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 80rpx;
    margin-bottom: 20rpx;
    font-size: 30rpx;
    font-weight: bold;
    color: #818181;
    border-bottom: 1px solid #e3e3e3;
  }

  .sign-main-show-line {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90%;
    padding: 20rpx;
    margin: 20rpx 0;
    border: 4rpx solid #d0dbff;
    border-radius: 10rpx;
  }

  .sign-main-show-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 80rpx;
    border-top: 1px solid #e3e3e3;
  }
}

.info-list {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.info-list-main {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 10rpx;
  margin: 10rpx 0;
  border: 1px solid #e3e3e3;
  border-radius: 8rpx;

  .info-list-row {
    display: flex;
    width: 100%;

    .info-list-label {
      width: 150rpx;
      font-size: 28rpx;
      color: #808080;
    }

    .info-list-value {
      display: flex;
      flex: 1;
      align-items: center;
      width: 0;
      word-break: break-all;
      white-space: pre-line;
    }
  }
}

.craft-row {
  display: flex;
  align-items: center;

  .craft-row-img-main {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    width: 0;
  }
}

.craft-row-img {
  width: 240rpx;
  height: 240rpx;
}

.form-demandDesc {
  align-items: flex-start !important;

  .text {
    word-break: break-all;
  }
}

// .info-row-item {
//   padding: 6rpx 0;
//   word-break: break-all;
// }

.info-row-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 6rpx 0;
  color: blue;
  word-break: break-all;
}

.text {
  word-break: break-all;
  word-wrap: break-word;
}

:deep(.wd-collapse-item__body) {
  padding: 0 !important;
}

// :deep(.wd-collapse-item__wrapper){
//   height:auto !important;
// }

:deep(.wd-collapse-item__body) {
  padding: 10rpx;
}

:deep(.wd-collapse-item__header) {
  padding-right: 10rpx;
  padding-left: 10rpx;
}

.exportModel {
  width: 100%;
  margin-top: 10rpx;
  font-size: 28rpx;
  color: #409eff;
  text-align: center;
}

:deep(.wd-textarea__inner) {
  min-height: 200rpx;
}
</style>
